<?php
session_start();
if (!$_SESSION["status"]) {
    header("location:../managerlogin.php");
}
include_once "../model/model.php";
include_once "../model/pile.php";
define("BUSY", "位置不足！");
define("ERROR", "系统错误");
if (isset($_POST["check"])) {
	if ($_POST["check"] === "1") {
		check($_POST["index"], $_POST["check"]);
		$connect = new CONNECT();
		$connect = $connect->connecttodb();
		$action = $connect->prepare("SELECT * FROM apply_site WHERE id = ?");
		$action->execute(array($_POST["index"]));
		$result = $action->fetchAll();
		if (count($result)) {
			//var_dump($result);
			//var_dump($_POST["index"]);
			$distribute = new REQUEST();
			$num = $distribute->site_rest($result[0][6], $result[0][7]);
			if ((12 - $num) >= $result[0][5]) {
				//echo "ok";
				if ($distribute->site_distribute($_POST["index"]) === "ok") {
					header("location:../admin/check.php");
					/* echo "<script>window.location.assign('../admin/check.php')</script>"; */
				};
			} else {
				$status = -1;
				/* echo "位置不足！"; */
				check($_POST["index"], 0);
			}
		} else {
			/* echo "系统错误"; */
			$status = -2;
		}
	} else if($_POST["check"] === "-1") {
		$connect = new CONNECT();
		$connect = $connect->connecttodb();
		$action = $connect->prepare("UPDATE `apply_site` SET `status`= -1 WHERE id = ?");
		$result = $action->execute(array($_POST["index"]));
		if ($result) {
			/* echo "<script>window.location.assign('../admin/check.php')</script>"; */
			header("location:../admin/check.php");
		}
	}
}

?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf8">
        <title>管理员审核表</title>

        <link rel="stylesheet" href="../public/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="../css/check.css">
    </head>
    <body>
        <div id = "main">

            </br>
            </br><br><br><br><br><br>


            <p><div id = "line6"></div></p>

        <h1 align="center"><strong>处理结果</strong></h1>

        <h2 align="center">
            <?php
            /* include_once "../model/model.php"; */
            /* include_once "../model/pile.php"; */
            /* if (isset($_POST["check"])) { */
            /*     if ($_POST["check"] === "1") { */
            /*         check($_POST["index"], $_POST["check"]); */
            /*         $connect = new CONNECT(); */
            /*         $connect = $connect->connecttodb(); */
            /*         $action = $connect->prepare("SELECT * FROM apply_site WHERE id = ?"); */
            /*         $action->execute(array($_POST["index"])); */
            /*         $result = $action->fetchAll(); */
            /*         if (count($result)) { */
            /*             //var_dump($result); */
            /*             //var_dump($_POST["index"]); */
            /*             $distribute = new REQUEST(); */
            /*             $num = $distribute->site_rest($result[0][6], $result[0][7]); */
            /*             if ((24 - $num) >= $result[0][5]) { */
            /*                 //echo "ok"; */
            /*                 if ($distribute->site_distribute($_POST["index"]) === "ok") { */
            /*                     /1* header("location:../admin/check.php"); *1/ */
								/* echo "<script>window.location.assign('../admin/check.php')</script>"; */
            /*                 }; */
            /*             } else { */
            /*                 echo "位置不足！"; */
            /*                 check($_POST["index"], 0); */
            /*             } */
            /*         } else { */
            /*             echo "系统错误"; */
            /*         } */
            /*     } else if($_POST["check"] === "-1") { */
            /*         $connect = new CONNECT(); */
            /*         $connect = $connect->connecttodb(); */
            /*         $action = $connect->prepare("UPDATE `apply_site` SET `status`= -1 WHERE id = ?"); */
            /*         $result = $action->execute(array($_POST["index"])); */
            /*         if ($result) { */
						/* echo "<script>window.location.assign('../admin/check.php')</script>"; */
            /*         } */
            /*     } */
            /* } */
            /* echo "<a href = '../admin/check.php'>返回</a>"; */
			if($status === -1)
			{
				echo BUSY;
			}
			else if($status === -2)
			{
				echo ERROR;
			}
			echo "<a href = '../admin/check.php'>返回</a>";
            ?>
        </h2>
</body>
</html>
